
function promiseAllSettled(promiseArr) {
  if(!Array.isArray(promiseArr)) {
    return Promise.reject(new TypeError('参数必须是数组'))
  }
  if(promiseArr.length===0) {
    return Promise.resolve([])
  }
  const wrappedPromises = promiseArr.map(p =>
    Promise.resolve(p).then(
      value => ({ status: 'fulfilled', value }),
      reason => ({ status: 'rejected', reason })
    )
  );
  return Promise.all(wrappedPromises);
}

/**
 * 兼容旧浏览器的polyfill
 */
// 检查环境是否原生支持 allSettled，不支持则添加 polyfill
if (!Promise.allSettled) {
  Promise.allSettled = function(promiseArr) {
    if(!Array.isArray(promiseArr)) {
      return Promise.reject(new TypeError('参数必须是数组'))
    }
    if(promiseArr.length===0) {
      return Promise.resolve([])
    }
    const wrappedPromises = promiseArr.map(p =>
      Promise.resolve(p).then(
        value => ({ status: 'fulfilled', value }),
        reason => ({ status: 'rejected', reason })
      )
    );
    return Promise.all(wrappedPromises);
  };
}